]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
cleanup: Use default parameters where appropriate
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 11 Jul 2019 23:31:38 +0000 (01:31 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Fri, 12 Jul 2019 18:54:49 +0000 (18:54 +0000)
Since ES6 it is possible to set an explicit default value for optional
parameters (overriding the implicit value of 'undefined'). Use them
for a nice small cleanup.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/626

js/misc/jsParse.js
js/ui/appDisplay.js
js/ui/barLevel.js
js/ui/components/autorunManager.js
js/ui/layout.js
js/ui/messageList.js
js/ui/messageTray.js
js/ui/osdWindow.js
js/ui/panel.js

index 5adc2d654722219f1799e666f98d35ec4ff9ceee..464e6bf8b324c47fae9b23bea5006f38556ce0d8 100644 (file)
@@ -151,11 +151,7 @@ function getAllProps(obj) {
 // e.g., expr="({ foo: null, bar: null, 4: null })" will
 // return ["foo", "bar", ...] but the list will not include "4",
 // since methods accessed with '.' notation must star with a letter or _.
-function getPropertyNamesFromExpression(expr, commandHeader) {
-    if (commandHeader == null) {
-        commandHeader = '';
-    }
-
+function getPropertyNamesFromExpression(expr, commandHeader = '') {
     let obj = {};
     if (!isUnsafeExpression(expr)) {
         try {
index ff771d30224574330876aff1f665ff5544d6d555..60322f81a70ac9b2929b817de4ec93154c79c48c 100644 (file)
@@ -1416,7 +1416,7 @@ var AppFolderPopup = class AppFolderPopup {
 Signals.addSignalMethods(AppFolderPopup.prototype);
 
 var AppIcon = class AppIcon {
-    constructor(app, iconParams) {
+    constructor(app, iconParams = {}) {
         this.app = app;
         this.id = app.get_id();
         this.name = app.get_name();
@@ -1442,9 +1442,6 @@ var AppIcon = class AppIcon {
 
         this.actor._delegate = this;
 
-        if (!iconParams)
-            iconParams = {};
-
         // Get the isDraggable property without passing it on to the BaseIcon:
         let appIconParams = Params.parse(iconParams, { isDraggable: true }, true);
         let isDraggable = appIconParams['isDraggable'];
index fe49b945dbcb95b45e5fd0fa4722d50d0f7433c2..b0e16d916bd2675ed13a894696659b5a9c055ca9 100644 (file)
@@ -4,7 +4,7 @@ const { Atk, Clutter, St } = imports.gi;
 const Signals = imports.signals;
 
 var BarLevel = class {
-    constructor(value, params) {
+    constructor(value, params = {}) {
         if (isNaN(value))
             // Avoid spreading NaNs around
             throw TypeError('The bar level value must be a number');
@@ -13,9 +13,6 @@ var BarLevel = class {
         this._overdriveStart = 1;
         this._barLevelWidth = 0;
 
-        if (params == undefined)
-            params = {};
-
         this.actor = new St.DrawingArea({ styleClass: params['styleClass'] || 'barlevel',
                                           can_focus: params['canFocus'] || false,
                                           reactive: params['reactive'] || false,
index 313edc9a86ef5219188ae298355cc7f93e5b4ab5..6d879013161bf6e16b80a17787c8646b6cbf2c4f 100644 (file)
@@ -122,10 +122,7 @@ var ContentTypeDiscoverer = class {
         }
     }
 
-    _emitCallback(mount, contentTypes) {
-        if (!contentTypes)
-            contentTypes = [];
-
+    _emitCallback(mount, contentTypes = []) {
         // we're not interested in win32 software content types here
         contentTypes = contentTypes.filter(
             type => (type != 'x-content/win32-software')
index dafcf8fb4f87fbc6d1061464f82726a92d19fd5b..66ea05dfe0f419859a9fd1865f0f75c3561cb204 100644 (file)
@@ -841,7 +841,7 @@ var LayoutManager = GObject.registerClass({
     // @params can have any of the same values as in addChrome(),
     // though some possibilities don't make sense. By default, @actor has
     // the same params as its chrome ancestor.
-    trackChrome(actor, params) {
+    trackChrome(actor, params = {}) {
         let ancestor = actor.get_parent();
         let index = this._findActor(ancestor);
         while (ancestor && index == -1) {
@@ -851,8 +851,6 @@ var LayoutManager = GObject.registerClass({
 
         let ancestorData = ancestor ? this._trackedActors[index]
                                     : defaultParams;
-        if (!params)
-            params = {};
         // We can't use Params.parse here because we want to drop
         // the extra values like ancestorData.actor
         for (let prop in defaultParams) {
index 5f7a0865c7f718d7a4513a956dd02adbac3194eb..c8f4b934630371b6e80aec76046cf498c6472a1d 100644 (file)
@@ -33,9 +33,7 @@ function _fixMarkup(text, allowMarkup) {
 }
 
 var URLHighlighter = class URLHighlighter {
-    constructor(text, lineWrap, allowMarkup) {
-        if (!text)
-            text = '';
+    constructor(text = '', lineWrap, allowMarkup) {
         this.actor = new St.Label({ reactive: true, style_class: 'url-highlighter',
                                     x_expand: true, x_align: Clutter.ActorAlign.START });
         this._linkColor = '#ccccff';
index 4a0a974b02ba0ec42f18a9b9ab1ea068b289f27a..f8c6c79e725046569134cb7f9dff947b994b783c 100644 (file)
@@ -473,9 +473,7 @@ var Notification = class Notification {
             this.destroy();
     }
 
-    destroy(reason) {
-        if (!reason)
-            reason = NotificationDestroyedReason.DISMISSED;
+    destroy(reason = NotificationDestroyedReason.DISMISSED) {
         this.emit('destroy', reason);
     }
 };
index 3730d6b20178b4372cec56b6e7cdae57977cb15f..2895ab5f37b621252d52eefe450475e5050dccde 100644 (file)
@@ -151,9 +151,7 @@ var OsdWindow = class {
         }
     }
 
-    setMaxLevel(maxLevel) {
-        if (maxLevel === undefined)
-            maxLevel = 100;
+    setMaxLevel(maxLevel = 100) {
         this._level.maxLevel = maxLevel;
     }
 
index 6b8e60b1950ce841993039b11d34fa139b3c8f0b..e36bf4c3558ccc03eaf54bc8dff490d8fdae9d72 100644 (file)
@@ -706,9 +706,7 @@ var PanelCorner = class {
 
 var AggregateLayout = GObject.registerClass(
 class AggregateLayout extends Clutter.BoxLayout {
-    _init(params) {
-        if (!params)
-            params = {};
+    _init(params = {}) {
         params['orientation'] = Clutter.Orientation.VERTICAL;
         super._init(params);